﻿using System;
using System.Data;
using System.Text;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;
using BugManager;
using ChannelVN.Cached.Base;

namespace GUI.Controls.News
{
    public partial class BoxNews2 : ControlBase
    {
        private const string Format = "<li>{3}<p class=\"desc overlay\"><a href=\"{0}\" title=\"{2}\" class=\"prop_title\">{1}</a></p></li>";
        private const int ImageWidth = 228;
        private const int ImageHeight = 170;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        internal bool DataBind(DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                var sb = new StringBuilder();
                foreach (DataRow r in dt.Rows)
                {
                    var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth, ImageHeight, lazyLoad: true);
                    sb.AppendFormat(Format,
                                    r[SqlConstants.NewsPublish.Url],
                                    r[SqlConstants.NewsPublish.Title],
                                    r[SqlConstants.NewsPublish.EncodedTitle],
                                    avatar);
                }
                ltrData.Text = sb.ToString();
                return true;
            }
            return false;
        }

        public override string CacheConfigName
        {
            get { return "Controls-News-BoxNews2"; }
        }

        public override bool IsCachedChanged(long newsId, string zoneId, long tagId)
        {
            return !string.IsNullOrEmpty(zoneId);
        }
    }
}